package flc.ast;

import android.view.View;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

import flc.ast.activity.CameraActivity;
import flc.ast.activity.InputPwdActivity;
import flc.ast.activity.SetPwdActivity;
import flc.ast.databinding.ActivityHomeBinding;
import flc.ast.fragment.HomeFragment;
import flc.ast.fragment.MyFragment;
import flc.ast.fragment.ToolFragment;
import flc.ast.fragment.VideoFragment;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelActivity;
import stark.common.basic.base.BaseTabFragmentHomeActivity;
import stark.common.basic.base.DefExitAppDialog;
import stark.common.basic.event.EventStatConstant;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.SPUtil;
import stark.common.basic.utils.StatusBarUtils;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> implements View.OnClickListener {

    @Override
    protected int getPageType() {
        return EventStatConstant.PAGE_TAB_HOME;
    }

    @Override
    protected void initView() {
        super.initView();
        EventStatProxy.getInstance().statLaunch(this);
        mDataBinding.llCamera.setOnClickListener(this);

        //判断是否设置密码
        boolean isHave = SPUtil.getBoolean(mContext, Content.isHavePassword, false);
        if (isHave) {
            InputPwdActivity.isShow = false;
            startActivity(InputPwdActivity.class);
        } else {
            startActivity(SetPwdActivity.class);
        }
    }

    @Override
    protected void onHandleStatusBar() {
        super.onHandleStatusBar();
        //设置状态栏字体颜色
        StatusBarUtils.setSystemStatusTextColor(true, this);
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(VideoFragment.class, R.id.llVideo));
        listFragment.add(new FragmentViewBinder(ToolFragment.class, R.id.llTool));
        listFragment.add(new FragmentViewBinder(MyFragment.class, R.id.llMy));
        return listFragment;
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.llCamera://相机
                startActivity(CameraActivity.class);
                break;
        }
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        switch (view.getId()) {
            case R.id.llHome:
                mDataBinding.ivHome.setImageResource(R.drawable.tab_1);
                break;
            case R.id.llVideo:
                mDataBinding.ivVideo.setImageResource(R.drawable.tab_2);
                break;
            case R.id.llTool:
                mDataBinding.ivTool.setImageResource(R.drawable.tab_3);
                break;
            case R.id.llMy:
                mDataBinding.ivMy.setImageResource(R.drawable.tab_4);
                break;
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flHome;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.tab_1a);
        mDataBinding.ivVideo.setImageResource(R.drawable.tab_2a);
        mDataBinding.ivTool.setImageResource(R.drawable.tab_3a);
        mDataBinding.ivMy.setImageResource(R.drawable.tab_4a);
    }

}